package com.zhiyume.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;


/**
 * 运行时异常处理
 * */
public class SysException extends RuntimeException{
	private static final long serialVersionUID = 1L;
	private Logger log = LoggerFactory.getLogger(AppException.class);
	private String msgId;
	private String message;
	private Exception exception;
	public String getMsgId() {
		return msgId;
	}
	public void setMsgId(String msgId) {
		this.msgId = msgId;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public Exception getException() {
		return exception;
	}
	public void setException(Exception exception) {
		this.exception = exception;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public SysException(String msgId, String message, Exception exception) {
		super();
		this.msgId = msgId;
		this.message = message;
		this.exception = exception;
		
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		PrintStream printStream = new PrintStream(outputStream);
		this.exception.printStackTrace(printStream);
		this.message = outputStream.toString().trim();
		this.writeSysException();
	}
	
	/**
	 * 将异常信息输入到
	 * 
	 * */
	public void writeSysException(){
		log.error("id:"+msgId);
	    log.error("msg:"+message);   
	    ByteArrayOutputStream outPutStream = new ByteArrayOutputStream();
	    PrintStream printStream = new PrintStream(outPutStream);
	    this.exception.printStackTrace(printStream);
	    log.error(outPutStream.toString());
	}

}
